<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>

<script type='text/javascript'>
function checkKPP() {
  AjaxHandler.isKPPValid(replyKPP, document.getElementById("kpp").value);
}

function replyKPP(valid) {
  processReply(valid, "kpp", "kpp-error", "Please enter a valid KPP");
}

function checkINN() {
  AjaxHandler.isINNValid(replyINN, document.getElementById("inn").value);
}

function replyINN(valid) {
  processReply(valid, "inn", "inn-error", "Please enter a valid INN");
}

function checkAccount1() {
  AjaxHandler.isAccountValid(replyAccount1, document.getElementById("account1").value);
}

function replyAccount1(valid) {
  processReply(valid, "account1", "account1-error", "Please enter a valid account");
}

function checkAccount2() {
  AjaxHandler.isAccountValid(replyAccount2, document.getElementById("account2").value);
}

function replyAccount2(valid) {
  processReply(valid, "account2", "account2-error", "Please enter a valid account");
}

function checkBIK() {
  AjaxHandler.isBIKValid(replyBIK, document.getElementById("bik").value);
}

function replyBIK(valid) {
  processReply(valid, "bik", "bik-error", "Please enter a valid bik");
}

function checkEmail1() {
  AjaxHandler.isEmailValid(replyEmail1, document.getElementById("email1").value);
}

function replyEmail1(valid) {
  processReply(valid, "email1", "email1-error", "Please enter a valid email");
}

function checkEmail2() {
  AjaxHandler.isEmailValid(replyEmail2, document.getElementById("email2").value);
}

function replyEmail2(valid) {
  processReply(valid, "email2", "email2-error", "Please enter a valid email");
}

function processReply(valid, id, errid, error) {
  if (valid) {
    DWRUtil.setValue(errid, "");
    $(id).style.color = "black";
  }
  else {
    DWRUtil.setValue(errid, error);
    $(id).style.color = "red";
  }
}
</script>

<h2><fmt:message key = "form.addeditOrganization"/></h2>

<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<form action = "operatorui" method = "post" name = "organizationAddEditForm">
   <table class = "form">      
      <tr>
         <td class = "label"><fmt:message key = "organization.shorttitle"/></td>
         <td><input name = "shorttitle" type = "text" value = '<c:out value = "${organizationBean.shortTitle}"/>'></td>
         <td></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.fulltitle"/></td>
         <td><input name = "fulltitle" type = "text" value = '<c:out value = "${organizationBean.fullTitle}"/>'></td>
         <td></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.postaladdress"/></td>
         <td><input name = "postaladdress" type = "text" value = '<c:out value = "${organizationBean.postalAddress}"/>'></td>
         <td></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.kpp"/></td>
         <td><input id="kpp" name = "kpp" type = "text" value = '<c:out value = "${organizationBean.kpp}"/>' onchange="checkKPP();"></td>
         <td><span id="kpp-error" class="error"></span></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.inn"/></td>
         <td><input id="inn" name = "inn" type = "text" value = '<c:out value = "${organizationBean.inn}"/>' onchange="checkINN();"></td>
         <td><span id="inn-error" class="error"></span></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.settlementaccount"/></td>
         <td><input id="account1" name = "settlementaccount" type = "text" value = '<c:out value = "${organizationBean.settlementAccount}"/>' onchange="checkAccount1();"></td>
         <td><span id="account1-error" class="error"></span></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.banktitle"/></td>
         <td><input name = "banktitle" type = "text" value = '<c:out value = "${organizationBean.bankTitle}"/>'></td>
         <td></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.corraccount"/></td>
         <td><input id="account2" name = "corraccount" type = "text" value = '<c:out value = "${organizationBean.corrAccount}"/>' onchange="checkAccount2();"></td>
         <td><span id="account2-error" class="error"></span></td>         
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.bik"/></td>
         <td><input id="bik" name = "bik" type = "text" value = '<c:out value = "${organizationBean.bik}"/>' onchange="checkBIK();"></td>
         <td><span id="bik-error" class="error"></span></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.tel1"/></td>
         <td><input name = "tel1" type = "text" value = '<c:out value = "${organizationBean.tel1}"/>'></td>
         <td></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.tel2"/></td>
         <td><input name = "tel2" type = "text" value = '<c:out value = "${organizationBean.tel2}"/>'></td>
         <td></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.fax"/></td>
         <td><input name = "fax" type = "text" value = '<c:out value = "${organizationBean.fax}"/>'></td>
         <td></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.email1"/></td>
         <td><input id="email1" name = "email1" type = "text" value = '<c:out value = "${organizationBean.email1}"/>' onchange="checkEmail1();"></td>
         <td><span id="email1-error" class="error"></span></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.email2"/></td>
         <td><input id="email2" name = "email2" type = "text" value = '<c:out value = "${organizationBean.email2}"/>' onchange="checkEmail2();"></td>
         <td><span id="email2-error" class="error"></span></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "organization.www"/></td>
         <td><input name = "www" type = "text" value = '<c:out value = "${organizationBean.www}"/>'></td>
         <td></td>
      </tr>
         
      <tr>
         <td class = "label"><fmt:message key = "organization.businesstype"/></td>
         <td><input name = "businesstype" type = "text" value = '<c:out value = "${organizationBean.businessType}"/>'></td>
         <td></td>
      </tr>
   </table>
   
   <table class = "form">      
      <tr>
         <td class = "label"><fmt:message key = "organization.notes"/></td>
         <td>
            <textarea name = "notes" rows="10" cols="50"><c:out value = "${organizationBean.notes}"/></textarea>
         </td>
         <td></td>
      </tr>     
   </table>
   
   <input name = "id" type = "hidden" value='<c:out value = "${organizationBean.id}"/>'>   
   <input name = "_action" type = "hidden">      
</form>


<div class="links">   
   <ul class = "navbar2">
      <li>
         <a href = 'javascript:doAction("processOrganizationForm");'>
            <fmt:message key = "Command.save"/>
         </a>
      </li>   
      <li>
         <a href = "javascript:reset();">
            <fmt:message key = "Command.reset"/>
         </a>
      </li>
      <li>   
         <a href = "operatorui?_action=listOrganizations">
            <fmt:message key = "Command.cancel"/>
         </a>                                  
      </li>     
    <ul>        
</div>